<?php
namespace app\index\controller;
use think\Controller;
use think\Db;
use think\Session;
class Login extends Controller
{
    // 登录页
    public function index()
    {
        return $this->fetch();
    }
    //处理登录
    public function login()
    {
        $data = [
            "user_phone"=>input('user_phone'),
            "user_pw"=>md5(input('user_pw')),
        ];
        // dump($data);
        // exit;
        $res = Db::name('user')->where($data)->find();
        // dump($res);
        // exit;
        if($res['status']==1){
            return $this->error('账号被冻结');
        }
        if($res==null){
            return $this->error('账号密码错误');
        }else{
            Session::set("user_id",$res["user_id"]);
            $this->success('登录成功','index/index');
        }
    }
    //注销功能
    public function logout(){
        Session::clear();
        $this->redirect("index/index");
    }
}
